from django.db import models

# Create your models here.
from utils.models import BaseModel
from user.models import UserInfo


class Address(models.Model):
    name = models.CharField(max_length=42, verbose_name='收货人姓名')
    tel = models.CharField(max_length=11, verbose_name='收货人手机号')
    isDefault = models.IntegerField(choices=((0, '非默认'), (1, '默认')), verbose_name='是否为默认收货地址')
    ship_address = models.IntegerField(choices=((0, '未选择'), (1, '已选择')), verbose_name='发货地址', default=0)
    province_name = models.CharField(max_length=64, verbose_name='省')
    city_name = models.CharField(max_length=64, verbose_name='城')
    region_name = models.CharField(max_length=64, verbose_name='区')
    detail_address = models.CharField(max_length=128, verbose_name='收件详细地址')

    user = models.ForeignKey(to=UserInfo, related_name='addressuser', on_delete=models.CASCADE, verbose_name='用户',
                             db_constraint=False)

    class Meta:
        db_table = 'shop_address'
        verbose_name_plural = '地址表'

    def __str__(self):
        return self.name

    def address(self):
        return (f'{self.province_name} {self.city_name} {self.region_name} {self.detail_address}')
